import React, { Component } from 'react'
import PubSub from 'pubsub-js'
export default class Show extends Component {

    state = {
        msg: ''
    }

    //组件挂载完毕
    componentDidMount(){
        PubSub.subscribe('keyword', (_, data) => {
            // console.log(data);
            this.setState({
                msg: data
            })
        });
    }

    render() {
        return (
            <div style={{width:'400px',height:'300px', border:'solid 1px #345'}}>
                {this.state.msg}
            </div>
        )
    }

    //组件将要卸载
    componentWillUnmount(){
        //取消订阅              频道
        PubSub.unsubscribe('keyword');
    }
}
